/*
 * AckleyFunction.cpp
 *
 *  Created on: 2010-01-13
 *      Author: adas
 */

#include <cmath>

#include "AckleyFunction.h"

double AckleyFunction::operator()(const Element & el)
{

	int n = el.getDimensionCount();
	double nDim = (double)n;
	double a = 20;
	double b = 0.2;
	double c = 2*M_PI;
	double s1 = 0, s2 = 0;

	for(int i = 0; i < n; ++i)
	{
		s1 += el.getValueAt(i)*el.getValueAt(i);
		s2 += cos(c*el.getValueAt(i));
	}

	//y = -a*exp(-b*sqrt(1/n*s1))-exp(1/n*s2)+a+exp(1);

	return -a*exp(-b*sqrt(1/nDim*s1))-exp(1/nDim*s2)+a+exp(1);

//	return (el.getValueAt(0)-2)*(el.getValueAt(0)-2) + (el.getValueAt(1)-3)*(el.getValueAt(1)-3) -6;

}
